package baidu.bms.consumer;

import org.apache.dubbo.common.extension.Activate;
import org.apache.dubbo.common.logger.Logger;
import org.apache.dubbo.common.logger.LoggerFactory;
import org.apache.dubbo.rpc.*;

import java.util.Map;

/**
 * @author sunqiyuan
 * @Classname DemoFilter
 * @Description TODO
 * @Date 2020/10/15 11:05 上午
 * @Version V1.0
 */
// 无论consumer 和 provider 统一激活
@Activate(group = {"provider", "consumer"})
public class DemoFilter1 implements Filter {
    private static final Logger logger = LoggerFactory.getLogger(DemoFilter1.class);

    @Override
    public Result invoke(Invoker<?> invoker, Invocation invocation) throws RpcException {

//        try {
//
//            Map<String, String> attachments = invocation.getAttachments();
//            attachments.put("traceId", "123456789");
//            System.out.println("hello DemoFilter1 !"+ invocation.getAttachments());
//        } catch (Throwable t) {
//            logger.warn("Exception in DemoFilter (" + invoker + ") when add attachments", t);
//        }
        return invoker.invoke(invocation);

    }
}
